import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:sph_driver/Login/LoginVIewController.dart';

import '../AppConfig/LocalStorage.dart';
import '../Tabbar/TabbarView.dart';


class GuidePage extends StatefulWidget {
  const GuidePage({super.key});

  @override
  State<GuidePage> createState() => _GuidePageState();
}

class _GuidePageState extends State<GuidePage> {
   Timer? _timer;
   bool isNav=false;
   // 上一次点击返回键的时间
   DateTime? lastPressed;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _timer = Timer.periodic(Duration(seconds: 2), (timer) {
      // 这里是你想要执行的操作
     setState(() {
       isNav=true;
     });
    });
  }
   @override
   void dispose() {
     // 在组件销毁时取消定时器，以防止内存泄漏
     _timer?.cancel();
     super.dispose();
   }
  @override
  Widget build(BuildContext context) {
    final screenSize = MediaQuery.of(context).size;
    return WillPopScope(
      onWillPop: () async {
        // 获取当前时间
        final now = DateTime.now();
        // 如果 lastPressed 为空或者间隔时间超过 2 秒，则更新 lastPressed 并提示用户
        if (lastPressed == null || now.difference(lastPressed!) > Duration(seconds: 2)) {
          lastPressed = now;
          ScaffoldMessenger.of(context).showSnackBar(
            SnackBar(
              content: Text('再按一次退出'),
              duration: Duration(seconds: 2),
            ),
          );
          return true; // 不退出
        }
        return true; // 退出应用
      },
      child: isNav?TabbarView(pateIndex: 0, ):Container(color: Color.fromRGBO(241, 231, 221, 1),child: Image.asset("lib/Images/login/启动页.png",width: screenSize.width, height: screenSize.height,),),
    );
    // return isNav?TabbarView(pateIndex: 0, ):Container(color: Colors.white,child: Image.asset("lib/Images/login/启动页.png",width: screenSize.width, height: screenSize.height,),);

  }
}